package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.DamageListDao;
import com.atguigu.jxc.dao.DamageListGoodsDao;
import com.atguigu.jxc.entity.DamageList;
import com.atguigu.jxc.entity.DamageListGoods;
import com.atguigu.jxc.service.DamageListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: lei
 * @Date 2021/11/26 20:09
 **/
@Service
public class DamageListServiceImpl implements DamageListService {
    @Autowired
    private DamageListDao damageListDao;

    @Autowired
    private DamageListGoodsDao damageListGoodsDao;

    // 同时添加damagelist，生成主键，保存集合
    @Override
    @Transactional
    public void save(DamageList damageList, List<DamageListGoods> damageListGoodsList) {
        damageListDao.insert(damageList);
        Integer damageListId = damageList.getDamageListId();
        damageListGoodsDao.insertList(damageListGoodsList,damageListId);
    }

    // 报损单查询
    @Override
    public Map listDamageList(String sTime, String eTime) {
        List listDamageList= damageListDao.listDamageList(sTime,eTime);
        Map map =new HashMap();
        map.put("rows",listDamageList);
        return map;
    }

    // 报损货物列表
    @Override
    public Map selectGoodsList(String damageListId) {
        List<DamageListGoods> damageListGoodsList = damageListGoodsDao.selectGoodsList(damageListId);
        Map map = new HashMap();
        map.put("rows",damageListGoodsList);
        return map;
    }
}
